//
//  CZVistorView.m
//  CY--OCweibo
//
//  Created by mac on 15/11/23.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "CZVistorView.h"

@interface CZVistorView ()
/**
 * 转盘
 */
@property (nonatomic, strong) UIImageView *iconView;
/**
 *  小房子
 */
@property (nonatomic, strong) UIImageView *homeView;
/**
 *  消息
 */
@property (nonatomic, strong) UILabel *messageLabel;
/**
 *  注册按钮
 */
@property (nonatomic, strong) UIButton *registerButton;
/**
 *  登录按钮
 */
@property (nonatomic, strong) UIButton *loginButton;
/**
 *  遮罩图片
 */
@property (nonatomic, strong) UIImageView *coverView;
@end

@implementation CZVistorView

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self =[super initWithCoder:aDecoder])
    {
        [self prepareUI];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self prepareUI];
    }
    
    return self;
}


- (void)prepareUI
{
    [self setBackgroundColor:[UIColor colorWithWhite:237/255.0 alpha:1]];
    //添加子控件
    [self addSubview:self.iconView];
    [self addSubview:self.coverView];
    [self addSubview:self.homeView];
    [self addSubview:self.messageLabel];
    [self addSubview:self.registerButton];
    [self addSubview:self.loginButton];
    //关闭Autoresizing,不让它干扰autlayout的约束
    self.iconView.translatesAutoresizingMaskIntoConstraints = false;
    self.coverView.translatesAutoresizingMaskIntoConstraints = false;
    self.homeView.translatesAutoresizingMaskIntoConstraints = false;
    
    self.messageLabel.translatesAutoresizingMaskIntoConstraints = false;
    self.registerButton.translatesAutoresizingMaskIntoConstraints = false;
    
    self.loginButton.translatesAutoresizingMaskIntoConstraints = false;
    
    //添加约束
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1 constant:-40]];
    //遮罩约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.registerButton attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.coverView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    
    
    //小房子
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
    //消息
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    //宽度约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:226]];
    
    //注册按钮
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    //宽
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:90]];
    //高
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:35]];
    //注册按钮
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    //宽
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:90]];
    //高
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:35]];
    
}

//转轮动画
- (void)rotationAnimation {


}

//设置访客视图
- (void)setupVistorView:(NSString *)imageName message:(NSString *)message{
    //替换转轮的图片
    self.iconView.image = [UIImage imageNamed:imageName];
    //文字
    self.messageLabel.text = message;
    //隐藏房子
    self.homeView.hidden = YES;
    //隐藏遮罩图片
    self.coverView.hidden = YES;

}

#pragma mark - 懒加载
- (UIImageView *)iconView
{
    if (_iconView==nil)
    {
        _iconView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
        
    }
    return _iconView;
}

- (UIImageView *)coverView
{
    if (_coverView==nil)
    {
        _coverView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
        
    }
    return _coverView;
}
- (UIImageView *)homeView
{
    if (_homeView==nil)
    {
        _homeView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeView;
}

- (UILabel *)messageLabel
{
    if (_messageLabel==nil)
    {
        _messageLabel=[[UILabel alloc] init];
        
        _messageLabel.textColor =[UIColor darkGrayColor];
        
        _messageLabel.text=@"关注一些人,看看有神马惊喜";
        [_messageLabel setNumberOfLines:0];
        [_messageLabel sizeToFit];
//        _messageLabel.frame = CGRectMake(100, 100, 100, 100);
    }
    return _messageLabel;
}
- (UIButton *)registerButton
{
    if (_registerButton==nil)
    {
       _registerButton =[[UIButton alloc] init];
        
        [_registerButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        [_registerButton setTitle:@"注册" forState:UIControlStateNormal];
        [_registerButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_registerButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        
        [_registerButton sizeToFit];
    }
    return _registerButton;
}
- (UIButton *)loginButton
{
    if (_loginButton==nil)
    {
        _loginButton =[[UIButton alloc] init];
        
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        [_loginButton setTitle:@"注册" forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_loginButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        
        [_loginButton sizeToFit];
    }
    return _loginButton;
}

@end
